<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/picker.css" />
		<link rel="stylesheet" href="../css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/datepicker3.css" />
		<link rel="stylesheet" href="../css/member.css" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a id="shan" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">农机资料</h1>
			<!--//<button class="mui-pull-right edit" id="btn" style="background-color: #ff7831;border: 0px;color: #efecec; font-size: 16px;">保存</button>-->
		</header>
		<div class="mui-content address_content">
			<form class="mui-input-group">
				<div class="address_mor clearfix">
					<span>是否工作</span>
					<div id="isdefault" class="mui-switch mui-switch-mini" data-mystate="1">
						<div class="mui-switch-handle"></div>
					</div>
				</div>
				<div class="mui-input-row mui-select">
					<label>农机类型：</label>
					<select id='nj_type'>
						<option value="">请选择农机类型</option>
					</select>
				</div>
				<div class="mui-input-row">
					<label>联系人：</label>
					<input type="text" id="contacts" class="mui-input-group" placeholder="请输入姓名">
				</div>
				<div class="mui-input-row">
					<label>联系电话：</label>
					<input type="text" id="tel" class="mui-input-group" placeholder="请输入联系电话">
				</div>
				<div class="mui-input-row">
					<label>农机名：</label>
					<input type="text" id="title" class="mui-input-group" placeholder="请输入农机名">
				</div>

				<div class="mui-input-row">
					<label>服务区域：</label>
					<input type="text" id="domain" readonly="readonly" class="mui-input-group" placeholder="请选择地区">

				</div>
				<div class="mui-input-row">
					<label>服务价格：</label>
					<input type="text" id="service_price" class="mui-input-group" placeholder="请输入服务价格">
				</div>
				<div class="mui-input-row">
					<label>服务开始时间 ：</label>
					<input type="text" name="birthday" id="service_time1" class="datetimepicker" id="datetimepicker" placeholder="请输入开始时间">
				</div>
				<div class="mui-input-row">
					<label>服务结束时间 ：</label>
					<input type="text" name="birthday" id="service_time2" class="datetimepicker" id="datetimepicker" placeholder="请输入结束时间">
				</div>

			</form>
			<div class="address_mor clearfix">
				<label class="col-sm-3 control-label">图文详情：</label>
				<strong>默认第一张主图</strong>

				<form class="mui-input-group gerenzl_group">
					<div class="gerenzl_top img-click">
						<div class="mui-input-row">
							<label>详情 ：</label>
							<textarea rows="3" cols="20" id="info" class="mui-text-center" placeholder="请输入详情"></textarea>
						</div>
						<div class="actions">
							<button class="file-btn" style="width: 60%; height: 30px;">
				               <span style="font-size: 15px;width: 60%;">上传图片</span>
				                <input type="file" id="upload" value="选择图片文件" multiple/>
				           </button>
							<hr>
							<div id="img_list" class="img_list">

							</div>
						</div>

					</div>

				</form>

				<div class="gerzl_btn" id="btn" onclick="func1()">
					<a href="#">发布</a>
				</div>
			</div>
			<input type="hidden" id='order_ids'>
			<script type="text/javascript" src="../js/jquery.min.js"></script>
			<script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
			<script src="../js/layer/layer.min.js"></script>
			<script src="../js/mui.min.js"></script>
			<script src="../js/castapp.js"></script>
			<script src="../js/picker.js"></script>
			<script src="../js/poppicker.js"></script>
			<script src="../js/city.data-3.js"></script>
			<script src="../js/app.js"></script>
			<script src="../js/ueditor/ueditor.config.js" type="text/javascript"></script>
			<script src="../js/ueditor/ueditor.all.js" type="text/javascript"></script>

			<script>
				//编辑器
				var member = JSON.parse(localStorage.getItem('member'));
				$(function() {
					//dlpd();
					ca.init();
					var btn = ca.id('btn');
					var input = ca.tagName('input');
					var dis = ca.id('domain');
					dis.addEventListener('tap', function() {
						//三级组合
						castapp.combinationSelect(3, cityData3, function(arr) {
							dis.value = arr;
						});
					});

					$(".datetimepicker").datepicker({
						language: "zh-CN",
						autoclose: true, //选中之后自动隐藏日期选择框
						clearBtn: true, //清除按钮
						todayBtn: true, //今日按钮
						format: "yyyy-mm-dd" //日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
					});
					$('#upload').on('change', function() {
						readFile(this, "thumb", 1, 10);
					});

					//获取分类
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/getnj_type",
						data: {
							id: member['id']
						},
						dataType: 'jsonp',
						success: function(data) {
							if(data.code == 200) {
								var type = data.list;
								var json = data.data;
								for(var i = 0; i < type.length; i++) {
									$('#nj_type').append('<option value=' + type[i]['id'] + '>' + type[i]['nj_type'] + '</option>');
								}
								document.getElementById("nj_type").options[data.data.title_type].selected = true;
								if(json.is_online == 2) {
									$("#isdefault2").css("transition-duration", "0.2s");
									$("#isdefault2").css("transform", "translate(16px, 0px)");
									$("#isdefault").addClass("mui-active");
									$("#isdefault").data("mystate", 2);
								}
								document.getElementById("contacts").value = json.contacts;
								document.getElementById("tel").value = json.tel;
								document.getElementById("title").value = json.title;
								document.getElementById("domain").value = json.address;
								document.getElementById("service_price").value = json.service_price;
								document.getElementById("service_time1").value = json.service_time1;
								document.getElementById("service_time2").value = json.service_time2;
								document.getElementById("info").value = json.info;
								var strs = json.img.split("@");
								for(var i = 0; i < strs.length; i++) {
									var innerHTML = '<div class="images-item">' +
										'	<span class="del">×</span>' +
										'	<img style="width: 90%;height: 150px; margin:0 auto;" src="' + APP.pic_url + strs[i] + '"/>' +
										'	<input calss="pic" type="hidden" name="pic_d" value="' + strs[i] + '" />' +
										'	<input id="p" type="hidden" name="' + i + '1" value="' + i + '" />' +
										'</div>';
									$("#img_list").append(innerHTML);
									del_event();
								}

							}
						},

					});

				});

				//获取传过来的图片
				function func1() {
					var isdefault = $("#isdefault").data("mystate");
					var x = document.getElementsByName("pic_d");
					var pic_d = "";
					var images = "";
					for(var i = 0; i < x.length; i++) {
						if(i == 0) {
							images += x[i].value;
							pic_d += x[i].value;
						} else {
							pic_d += '@' + x[i].value;
						}

					}

					if($("#nj_type").val() == '') {
						layer.msg('请选择分类', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($("#contacts").val() == '') {
						layer.msg('请填写联系人', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($("#tel").val() == '') {
						layer.msg('请填写联系电话', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($("#title").val() == '') {
						layer.msg('请填写产品名称', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($('#domain').val() == '') {
						layer.msg('请填写地址', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($('#service_price').val() == '') {
						layer.msg('售价不能为空', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}

					if($('#service_time1').val() == '') {
						layer.msg('生产时间不能为空', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if($('#service_time').val() == '') {
						layer.msg('结束时间不能为空', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					if(pic_d == "") {
						layer.msg('请上传图片', {
							icon: 1,
							time: 1500,
							shade: 0.1
						})
						return false;
					}
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/cre_nj",
						data: {
							is_online: isdefault, //是否附近
							member_id: member['id'],
							nj_type: $('#nj_type').val(),
							contacts: $("#contacts").val(),
							tel: $('#tel').val(),
							title: $('#title').val(),
							domain: $('#domain').val(),
							service_time1: $('#service_time1').val(),
							service_time2: $('#service_time2').val(),
							service_price: $('#service_price').val(),
							info: $('#info').val(),
							images: pic_d,
						},
						dataType: 'jsonp',
						success: function(data) {
							layer.msg(data.msg, {
								icon: 1,
								time: 1500,
								shade: 0.1
							}, function(index) {
								window.location.href = "member_index.html";
							});
						},

					});

				}
			</script>

			<script>
				$("#isdefault").click(function() {
					var my = $("#isdefault").data("mystate");
					var my_state = 1;
					if(parseInt(my) == 1) {
						$("#isdefault").data("mystate", 2);
					} else {
						$("#isdefault").data("mystate", 1);
					}
				})
			</script>